<?php
//fwrite($fp, C_WriteBlock(array(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)));
//usleep(50*1000);
//fwrite($fp, C_WriteBlock(array(0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)));
//usleep(50*1000);
//fwrite($fp, C_WriteBlock(array(0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)));

include("netronix.php");

$name = "kurwa_dziala";
$locker = "456";
$coffee = "50";
$name_char = unpack('C*',$name);
$locker_char = unpack('C*',$locker);
$coffee_char = unpack('C*',$coffee);

$fp = fsockopen("localhost", 5332, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
for($i=0;$i<2;$i++) {
fwrite($fp, C_Login_User(array(0x31, 0x32, 0x33, 0x34, 0x00)));
usleep(50*1000);
fwrite($fp, C_SetAutoReaderConfig(array(0x00, 0x00, 0x01, 0x01, 0x00)));
usleep(50*1000);
fwrite($fp, C_LoadKeyToSKB(array(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00)));
usleep(50*1000);
fwrite($fp, C_TurnOnAntennaPower(array(0x01)));
usleep(50*1000);
fwrite($fp, C_Select(array(0x00)));
usleep(50*1000);
fwrite($fp, C_LoginWithSKB(array(0x02, 0xBB, 0x00)));
usleep(50*1000);
@fwrite($fp, C_WriteBlock(array(0x00, 37, $name_char[1], $name_char[2], $name_char[3], $name_char[4], $name_char[5], $name_char[6], $name_char[7], $name_char[8], $name_char[9], $name_char[10], $name_char[11], $name_char[12], $name_char[13], $name_char[14], 37)));
usleep(50*1000);
@fwrite($fp, C_WriteBlock(array(0x01, 37, $locker_char[1], $locker_char[2], $locker_char[3], $locker_char[4], 37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)));
usleep(50*1000);
@fwrite($fp, C_WriteBlock(array(0x02, 37, $coffee_char[1], $coffee_char[2], $coffee_char[3], $coffee_char[4], 37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)));
usleep(50*1000);
stream_set_timeout($fp, 1);
$rfid_data = fgets($fp, 55);
$hex = unpack('C*',$rfid_data);
$hex_string = implode($hex, "");
echo "HEX: ".$hex_string."\n\n\n";
}
//if (strpos($hex_string,'16179255145186168925511019516232556401617255234166') !== false) {
//    echo 'true';
//} else {
//	goto rfid_save_start;
//	}
}
sleep(1);
fwrite($fp, C_Login_User(array(0x31, 0x32, 0x33, 0x34, 0x00)));
usleep(50*1000);
fwrite($fp, C_SetAutoReaderConfig(array(0x01, 0x00, 0x01, 0x011, 0x01)));
//goto rfid_save_start;
?>